package com.infore.qualityControl.service.impl;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.infore.qualityControl.bo.QualityParamSelectBo;
import com.infore.qualityControl.constant.Constants;
import com.infore.qualityControl.enums.QualityProjectEnum;
import com.infore.qualityControl.enums.ResultStatus;
import com.infore.qualityControl.po.AutomaticAndManualComparison;
import com.infore.qualityControl.po.FiveParameter;
import com.infore.qualityControl.po.RealWaterSampleComparison;
import com.infore.qualityControl.po.SpanDrift;
import com.infore.qualityControl.po.ZeroDrift;
import com.infore.qualityControl.repository.IAutomaticAndManualComparisonRepository;
import com.infore.qualityControl.repository.IFiveParameterRepository;
import com.infore.qualityControl.repository.IRealWaterSampleComparisonRepository;
import com.infore.qualityControl.repository.ISpanDriftRepository;
import com.infore.qualityControl.repository.IZeroDriftRepository;
import com.infore.qualityControl.select.util.PageObject;
import com.infore.qualityControl.service.ICQTestDataService;
import com.infore.qualityControl.service.IVerificationService;
import com.infore.qualityControl.util.ArrayUtils;
import com.infore.qualityControl.util.DateUtil;
import com.infore.qualityControl.util.Page;
import com.infore.qualityControl.util.PageUtil;
import com.infore.qualityControl.util.ResultEntity;

@Service
public class CQTestDataServiceImpl implements ICQTestDataService {
	
	@Autowired
	IZeroDriftRepository IZeroDriftRepository;
	
	@Autowired
	ISpanDriftRepository ISpanDriftRepository;
	
	@Autowired
	IFiveParameterRepository IFiveParameterRepository;
	
	@Autowired
	IRealWaterSampleComparisonRepository IRealWaterSampleComparisonRepository;
	
	@Autowired
	IAutomaticAndManualComparisonRepository IAutomaticAndManualComparisonRepository;
	
	@Autowired
	IVerificationService IVerificationService;

	@Override
	public ResultEntity zeroSpanCheckData(QualityParamSelectBo qualityParamSelectBo, PageObject pageObject) {
		boolean pageFlag = pageObject.getPageNumber() != null && pageObject.getPageSize() != null;
		// 验证参数
		ResultEntity resultEntity = IVerificationService.verification(qualityParamSelectBo);
		if (resultEntity.getCode() == 1) {
			return resultEntity;
		}
		Date startDate = DateUtil.stringToDate(qualityParamSelectBo.getStartTime(), DateUtil.DATE_SMALL_YMDHMS);
		Date endDate = DateUtil.stringToDate(qualityParamSelectBo.getEndTime(), DateUtil.DATE_SMALL_YMDHMS);
		// 字符串转集合
		List<String> indexList = ArrayUtils.stringToList(qualityParamSelectBo.getIndexCodes());
		List<String> stationCodeList = ArrayUtils.stringToList(qualityParamSelectBo.getStationCodes());
		// 获取零点数据(包含核查与漂移)
		List<ZeroDrift> zeroList = IZeroDriftRepository.findByTimeBetweenAndIndexCodeInAndStationCodeInOrderByTimeDesc(
				startDate, endDate, indexList, stationCodeList);
		// 获取跨度数据(包含核查与漂移)
		List<SpanDrift> spanList = ISpanDriftRepository.findByTimeBetweenAndIndexCodeInAndStationCodeInOrderByTimeDesc(
				startDate, endDate, indexList, stationCodeList);
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		for (ZeroDrift zeroDrift : zeroList) {
			String stationCode = zeroDrift.getStationCode();
			String zeroValue = zeroDrift.getValue(); // 零点核查系统值
			String zeroStandardSamplesValue = zeroDrift.getStandardSamplesValue(); // 零点核查校正液浓度值
			String zeroAbsoluteError = zeroDrift.getAbsoluteError(); // 零点核查绝对误差
			String zeroAbsoluteTechnicalRequirement = zeroDrift.getAbsoluteTechnicalRequirement(); // 零点核查绝对误差范围
			String zeroTime = DateUtil.dateToString(zeroDrift.getTime(), DateUtil.DATE_SMALL_YMDHMS);
			Map<String, Object> map = new HashMap<String, Object>();
//			if ("40000000000001".equals(stationCode) || "40000000000002".equals(stationCode)) {
				map.put("time", zeroTime);
				map.put("zeroValue", zeroValue);
				map.put("zeroStandardSamplesValue", zeroStandardSamplesValue);
				map.put("zeroAbsoluteError", zeroAbsoluteError);
				map.put("zeroAbsoluteTechnicalRequirement", zeroAbsoluteTechnicalRequirement);
//			}
			for (SpanDrift spanDrift : spanList) {
				String spanValue = spanDrift.getValue(); // 跨度核查系统值
				String spanStandardSamplesValue = spanDrift.getStandardSamplesValue(); // 跨度核查校正液浓度值
				String spanCheckRelativeError = spanDrift.getCheckRelativeError(); // 跨度核查相对误差
				String spanCheckRelativeTechnicalRequirement = spanDrift.getCheckTechnicalRequirement(); // 跨度核查相对误差范围
				String spanTime = DateUtil.dateToString(spanDrift.getTime(), DateUtil.DATE_SMALL_YMDHMS); 
				// 需要在零点漂移的时间基础上加上一小时
//				String spanTime = DateUtil.addHour(spanDrift.getTime(), -1, DateUtil.DATE_SMALL_YMDHMS);
				if (zeroTime.equals(spanTime)) { // 由于零点核查与跨度核查的时间点不一致，时间转换为年月日匹配
					map.put("spanValue", spanValue);
					map.put("spanStandardSamplesValue", spanStandardSamplesValue);
					map.put("spanCheckRelativeError", spanCheckRelativeError);
					map.put("spanCheckRelativeTechnicalRequirement", spanCheckRelativeTechnicalRequirement);
//					break;
				} else {
					map.put("spanValue", "");
					map.put("spanStandardSamplesValue", "");
					map.put("spanCheckRelativeError", "");
					map.put("spanCheckRelativeTechnicalRequirement", "");
				}
			}
			if (!map.isEmpty()) {
				list.add(map);
			}
		}
		for (SpanDrift spanDrift : spanList) {
			String spanValue = spanDrift.getValue(); // 跨度核查系统值
			String stationCode = spanDrift.getStationCode();
			String spanStandardSamplesValue = spanDrift.getStandardSamplesValue(); // 跨度核查校正液浓度值
			String spanCheckRelativeError = spanDrift.getCheckRelativeError(); // 跨度核查相对误差
			String spanCheckRelativeTechnicalRequirement = spanDrift.getCheckTechnicalRequirement(); // 跨度核查相对误差范围
			String spanTime = DateUtil.dateToString(spanDrift.getTime(), DateUtil.DATE_SMALL_YMDHMS); 
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("time", spanTime);
			map.put("spanValue", spanValue);
			map.put("spanStandardSamplesValue", spanStandardSamplesValue);
			map.put("spanCheckRelativeError", spanCheckRelativeError);
			map.put("spanCheckRelativeTechnicalRequirement", spanCheckRelativeTechnicalRequirement);
			for (ZeroDrift zeroDrift : zeroList) {
				String zeroValue = zeroDrift.getValue(); // 零点核查系统值
				String zeroStandardSamplesValue = zeroDrift.getStandardSamplesValue(); // 零点核查校正液浓度值
				String zeroAbsoluteError = zeroDrift.getAbsoluteError(); // 零点核查绝对误差
				String zeroAbsoluteTechnicalRequirement = zeroDrift.getAbsoluteTechnicalRequirement(); // 零点核查绝对误差范围
				String zeroTime = DateUtil.dateToString(zeroDrift.getTime(), DateUtil.DATE_SMALL_YMDHMS);
				// 需要在零点漂移的时间基础上加上一小时
//				String spanTime = DateUtil.addHour(spanDrift.getTime(), -1, DateUtil.DATE_SMALL_YMDHMS);
				if (zeroTime.equals(spanTime)) { // 由于零点核查与跨度核查的时间点不一致，时间转换为年月日匹配
					map.put("zeroValue", zeroValue);
					map.put("zeroStandardSamplesValue", zeroStandardSamplesValue);
					map.put("zeroAbsoluteError", zeroAbsoluteError);
					map.put("zeroAbsoluteTechnicalRequirement", zeroAbsoluteTechnicalRequirement);
//					break;
				} else {
					map.put("zeroValue", "");
					map.put("zeroStandardSamplesValue", "");
					map.put("zeroAbsoluteError", "");
					map.put("zeroAbsoluteTechnicalRequirement", "");
				}
			}
			if (!map.isEmpty()) {
				list.add(map);
			}
		}
		//排序 默认按照时间降序排序
		Collections.sort(list, new Comparator<Map<String, Object>>() {
			@Override
			public int compare(Map<String, Object> map1, Map<String, Object> map2) {
				Long l1 = 0L;
				Long l2 = 0L;
				try {
					if(map1.get("time")!=null) {
						l1 = DateUtil.stringToDate(map1.get("time").toString(), DateUtil.DATE_SMALL_YMDHMS).getTime();
					}
					if(map2.get("time")!=null) {
						l2 = DateUtil.stringToDate(map2.get("time").toString(), DateUtil.DATE_SMALL_YMDHMS).getTime();
					}
				} catch (Exception e) {
					e.printStackTrace();
				}
				return l2>l1?1:-1;
			}
		});
		if (pageFlag) {
			Page<Map<String, Object>> page = PageUtil.inventedPage(list, pageObject);
			return new ResultEntity(ResultStatus.SUCCESS, Constants.QUERY_SUCCESS).setPage(page);
		}
		return new ResultEntity(ResultStatus.SUCCESS, Constants.QUERY_SUCCESS).setDataList(list);
	}

	@Override
	public ResultEntity zeroSpanDriftData(QualityParamSelectBo qualityParamSelectBo, PageObject pageObject) {
		boolean pageFlag = pageObject.getPageNumber() != null && pageObject.getPageSize() != null;
		// 验证参数
		ResultEntity resultEntity = IVerificationService.verification(qualityParamSelectBo);
		if (resultEntity.getCode() == 1) {
			return resultEntity;
		}
		Date startDate = DateUtil.stringToDate(qualityParamSelectBo.getStartTime(), DateUtil.DATE_SMALL_YMDHMS);
		Date endDate = DateUtil.stringToDate(qualityParamSelectBo.getEndTime(), DateUtil.DATE_SMALL_YMDHMS);
		// 字符串转集合
		List<String> indexList = ArrayUtils.stringToList(qualityParamSelectBo.getIndexCodes());
		List<String> stationCodeList = ArrayUtils.stringToList(qualityParamSelectBo.getStationCodes());
		// 获取零点数据(包含核查与漂移)
		List<ZeroDrift> zeroList = IZeroDriftRepository.findByTimeBetweenAndIndexCodeInAndStationCodeInOrderByTimeDesc(
				startDate, endDate, indexList, stationCodeList);
		// 获取跨度数据(包含核查与漂移)
		List<SpanDrift> spanList = ISpanDriftRepository.findByTimeBetweenAndIndexCodeInAndStationCodeInOrderByTimeDesc(
				startDate, endDate, indexList, stationCodeList);
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		for (ZeroDrift zeroDrift : zeroList) {
			String stationCode = zeroDrift.getStationCode();
			String zeroValue = zeroDrift.getValue(); // 零点漂移系统值
			String zeroLastValue = zeroDrift.getLastValue(); // 零点漂移前24小时系统值
			String zeroRelativeError = zeroDrift.getRelativeError(); // 零点核查相对误差
			if (!"".equals(zeroRelativeError) && !"-".equals(zeroRelativeError)) {
				zeroRelativeError = zeroRelativeError + "%";
			}
			String zeroRelativeTechnicalRequirement = zeroDrift.getRelativeTechnicalRequirement(); // 零点核查相对误差范围
			String zeroTime = DateUtil.dateToString(zeroDrift.getTime(), DateUtil.DATE_SMALL_YMDHMS);
			Map<String, Object> map = new HashMap<String, Object>();
//			if ("40000000000001".equals(stationCode) || "40000000000002".equals(stationCode)) {
				map.put("time", zeroTime);
				map.put("zeroValue", zeroValue);
				map.put("zeroLastValue", zeroLastValue);
				map.put("zeroRelativeError", zeroRelativeError);
				map.put("zeroRelativeTechnicalRequirement", zeroRelativeTechnicalRequirement);
//			}
			for (SpanDrift spanDrift : spanList) {
				String spanValue = spanDrift.getValue(); // 跨度漂移系统值
				String spanLastValue = spanDrift.getLastValue(); // 跨度漂移前24小时系统值
				String spanDriftRelativeError = spanDrift.getDriftRelativeError(); // 跨度漂移相对误差
				if (!"".equals(spanDriftRelativeError) && !"-".equals(spanDriftRelativeError)) {
					spanDriftRelativeError = spanDriftRelativeError + "%";
				}
				String spanDriftRelativeTechnicalRequirement = spanDrift.getDriftTechnicalRequirement(); // 跨度漂移相对误差范围
				String spanTime = DateUtil.dateToString(spanDrift.getTime(), DateUtil.DATE_SMALL_YMDHMS); 
				// 需要在零点漂移的时间基础上加上一小时
//				String spanTime = DateUtil.addHour(spanDrift.getTime(), -1, DateUtil.DATE_SMALL_YMDHMS);
				if (zeroTime.equals(spanTime)) {
					map.put("spanValue", spanValue);
					map.put("spanLastValue", spanLastValue);
					map.put("spanDriftRelativeError", spanDriftRelativeError);
					map.put("spanDriftRelativeTechnicalRequirement", spanDriftRelativeTechnicalRequirement);
//					break;
				} else {
					map.put("spanValue", "");
					map.put("spanLastValue", "");
					map.put("spanDriftRelativeError", "");
					map.put("spanDriftRelativeTechnicalRequirement", "");
				}
			}
			if (!map.isEmpty()) {
				list.add(map);
			}
		}
		for (SpanDrift spanDrift : spanList) {
			String stationCode = spanDrift.getStationCode();
			String spanValue = spanDrift.getValue(); // 跨度漂移系统值
			String spanLastValue = spanDrift.getLastValue(); // 跨度漂移前24小时系统值
			String spanDriftRelativeError = spanDrift.getDriftRelativeError(); // 跨度漂移相对误差
			if (!"".equals(spanDriftRelativeError) && !"-".equals(spanDriftRelativeError)) {
				spanDriftRelativeError = spanDriftRelativeError + "%";
			}
			String spanDriftRelativeTechnicalRequirement = spanDrift.getDriftTechnicalRequirement(); // 跨度漂移相对误差范围
			String spanTime = DateUtil.dateToString(spanDrift.getTime(), DateUtil.DATE_SMALL_YMDHMS); 
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("time", spanTime);
			map.put("spanValue", spanValue);
			map.put("spanLastValue", spanLastValue);
			map.put("spanDriftRelativeError", spanDriftRelativeError);
			map.put("spanDriftRelativeTechnicalRequirement", spanDriftRelativeTechnicalRequirement);
			for (ZeroDrift zeroDrift : zeroList) {
				String zeroValue = zeroDrift.getValue(); // 零点漂移系统值
				String zeroLastValue = zeroDrift.getLastValue(); // 零点漂移前24小时系统值
				String zeroRelativeError = zeroDrift.getRelativeError(); // 零点核查相对误差
				if (!"".equals(zeroRelativeError) && !"-".equals(zeroRelativeError)) {
					zeroRelativeError = zeroRelativeError + "%";
				}
				String zeroRelativeTechnicalRequirement = zeroDrift.getRelativeTechnicalRequirement(); // 零点核查相对误差范围
				String zeroTime = DateUtil.dateToString(zeroDrift.getTime(), DateUtil.DATE_SMALL_YMDHMS);
				// 需要在零点漂移的时间基础上加上一小时
//				String spanTime = DateUtil.addHour(spanDrift.getTime(), -1, DateUtil.DATE_SMALL_YMDHMS);
				if (zeroTime.equals(spanTime)) {
					map.put("zeroValue", zeroValue);
					map.put("zeroLastValue", zeroLastValue);
					map.put("zeroRelativeError", zeroRelativeError);
					map.put("zeroRelativeTechnicalRequirement", zeroRelativeTechnicalRequirement);
//					break;
				} else {
					map.put("zeroValue", "");
					map.put("zeroLastValue", "");
					map.put("zeroRelativeError", "");
					map.put("zeroRelativeTechnicalRequirement", "");
				}
			}
			if (!map.isEmpty()) {
				list.add(map);
			}
		}
		//排序 默认按照时间降序排序
		Collections.sort(list, new Comparator<Map<String, Object>>() {
			@Override
			public int compare(Map<String, Object> map1, Map<String, Object> map2) {
				Long l1 = 0L;
				Long l2 = 0L;
				try {
					if(map1.get("time")!=null) {
						l1 = DateUtil.stringToDate(map1.get("time").toString(), DateUtil.DATE_SMALL_YMDHMS).getTime();
					}
					if(map2.get("time")!=null) {
						l2 = DateUtil.stringToDate(map2.get("time").toString(), DateUtil.DATE_SMALL_YMDHMS).getTime();
					}
				} catch (Exception e) {
					e.printStackTrace();
				}
				return l2>l1?1:-1;
			}
		});
		if (pageFlag) {
			Page<Map<String, Object>> page = PageUtil.inventedPage(list, pageObject);
			return new ResultEntity(ResultStatus.SUCCESS, Constants.QUERY_SUCCESS).setPage(page);
		}
		return new ResultEntity(ResultStatus.SUCCESS, Constants.QUERY_SUCCESS).setDataList(list);
	}
	
	@Override
	public ResultEntity fiveParameterData(QualityParamSelectBo qualityParamSelectBo, PageObject pageObject) {
		boolean pageFlag = pageObject.getPageNumber() != null && pageObject.getPageSize() != null;
		// 验证参数
		ResultEntity resultEntity = IVerificationService.verification(qualityParamSelectBo);
		if (resultEntity.getCode() == 1) {
			return resultEntity;
		}
		Date startDate = null;
		Date endDate = null;
		List<String> indexList = ArrayUtils.stringToList(qualityParamSelectBo.getIndexCodes());
		List<String> stationCodeList = ArrayUtils.stringToList(qualityParamSelectBo.getStationCodes());
		// 获取时间范围内的各个时间点数据
		List<String> timeList = DateUtil.getTimeList(qualityParamSelectBo.getStartTime(), qualityParamSelectBo.getEndTime(), DateUtil.DATE_SMALL_STR, "day");
		String time = "";
		for (String string : timeList) {
			Calendar c = Calendar.getInstance();
			c.setTime(DateUtil.stringToDate(string, DateUtil.DATE_SMALL_STR));
			int i_week_day = c.get(Calendar.DAY_OF_WEEK);
			if (i_week_day == 2) { // 代表周一
				time = string;
				break;
			}
		}
		List<FiveParameter> list = new ArrayList<>();
		for (String string : indexList) {
			List<FiveParameter> subList = null;
			if (string.equals(QualityProjectEnum.PH.getCode())) {
				startDate = DateUtil.stringToDate(time + " 10:25:00", DateUtil.DATE_FULL_STR);
				endDate = DateUtil.stringToDate(time + " 10:30:00", DateUtil.DATE_FULL_STR);
				subList = IFiveParameterRepository.findByTimeBetweenAndIndexCodeAndStationCodeInOrderByTimeAsc(startDate,
						endDate, string, stationCodeList);
			} else if (string.equals(QualityProjectEnum.WT.getCode())) {
				startDate = DateUtil.stringToDate(time + " 10:45:00", DateUtil.DATE_FULL_STR);
				endDate = DateUtil.stringToDate(time + " 10:50:00", DateUtil.DATE_FULL_STR);
				subList = IFiveParameterRepository.findByTimeBetweenAndIndexCodeAndStationCodeInOrderByTimeAsc(startDate,
						endDate, string, stationCodeList);
			} else if (string.equals(QualityProjectEnum.DO.getCode())) {
				startDate = DateUtil.stringToDate(time + " 10:45:00", DateUtil.DATE_FULL_STR);
				endDate = DateUtil.stringToDate(time + " 10:50:00", DateUtil.DATE_FULL_STR);
				subList = IFiveParameterRepository.findByTimeBetweenAndIndexCodeAndStationCodeInOrderByTimeAsc(startDate,
						endDate, string, stationCodeList);
			} else if (string.equals(QualityProjectEnum.EC.getCode())) {
				startDate = DateUtil.stringToDate(time + " 10:35:00", DateUtil.DATE_FULL_STR);
				endDate = DateUtil.stringToDate(time + " 10:40:00", DateUtil.DATE_FULL_STR);
				subList = IFiveParameterRepository.findByTimeBetweenAndIndexCodeAndStationCodeInOrderByTimeAsc(startDate,
						endDate, string, stationCodeList);
			} else if (string.equals(QualityProjectEnum.TUB.getCode())) {
				startDate = DateUtil.stringToDate(time + " 10:15:00", DateUtil.DATE_FULL_STR);
				endDate = DateUtil.stringToDate(time + " 10:20:00", DateUtil.DATE_FULL_STR);
				subList = IFiveParameterRepository.findByTimeBetweenAndIndexCodeAndStationCodeInOrderByTimeAsc(startDate,
						endDate, string, stationCodeList);
			}
			list.addAll(subList);
		}
		Collections.sort(list, new Comparator<FiveParameter>() {//表头排序
			public int compare(FiveParameter f1, FiveParameter f2) {
				int a = 0;
				if (f1.getIndexCode().equals(QualityProjectEnum.TUB.getCode()) || f1.getIndexCode().equals(QualityProjectEnum.PH.getCode())
						 || f1.getIndexCode().equals(QualityProjectEnum.EC.getCode())) {
					a = f1.getTime().compareTo(f2.getTime());
				}
				return a;
			}
		});
		if (pageFlag) {
			return new ResultEntity(ResultStatus.SUCCESS, Constants.QUERY_SUCCESS).setPage(PageUtil.inventedObjectPage(list, pageObject));
		}
		
		// 当前断面
//		if (qualityParamSelectBo.getIfCurrentSection()) {
//			if (pageFlag) {
//				Page<FiveParameter> page = PageUtil.pageConvert(
//						IFiveParameterRepository.findByTimeBetweenAndIndexCodeInAndStationCodeInOrderByTimeDesc(
//								startDate, endDate, indexList, stationCodeList, pageObject.getPageRequest()));
//				return new ResultEntity(ResultStatus.SUCCESS, Constants.QUERY_SUCCESS).setPage(page);
//			}
//			list = IFiveParameterRepository.findByTimeBetweenAndIndexCodeInAndStationCodeInOrderByTimeDesc(startDate,
//					endDate, indexList, stationCodeList);
//		} else {
//			// 前端传入区域编码以站点编码参数名传递即可
//			if (pageFlag) {
//				Page<FiveParameter> page = PageUtil.pageConvert(
//						IFiveParameterRepository.findByTimeBetweenAndIndexCodeInAndAreaCodeInOrderByTimeDesc(startDate,
//								endDate, indexList, stationCodeList, pageObject.getPageRequest()));
//				return new ResultEntity(ResultStatus.SUCCESS, Constants.QUERY_SUCCESS).setPage(page);
//			}
//			list = IFiveParameterRepository.findByTimeBetweenAndIndexCodeInAndAreaCodeInOrderByTimeDesc(startDate,
//					endDate, indexList, stationCodeList);
//		}
		return new ResultEntity(ResultStatus.SUCCESS, Constants.QUERY_SUCCESS).setDataList(list);
	}

	@Override
	public ResultEntity realWaterSampleComparisonData(QualityParamSelectBo qualityParamSelectBo,
			PageObject pageObject) {
		boolean pageFlag = pageObject.getPageNumber() != null && pageObject.getPageSize() != null;
		// 验证参数
		ResultEntity resultEntity = IVerificationService.verification(qualityParamSelectBo);
		if (resultEntity.getCode() == 1) {
			return resultEntity;
		}
		Date startDate = DateUtil.dangyueDiyitianMonth(
				DateUtil.stringToDate(qualityParamSelectBo.getStartTime(), DateUtil.DATE_SMALL_YM),
				DateUtil.DATE_FULL_STR);
		Date endDate = DateUtil.getLastDayMonthM(
				DateUtil.stringToDate(qualityParamSelectBo.getEndTime(), DateUtil.DATE_SMALL_YM),
				DateUtil.DATE_FULL_STR);
		List<String> indexList = ArrayUtils.stringToList(qualityParamSelectBo.getIndexCodes());
		List<String> stationCodeList = ArrayUtils.stringToList(qualityParamSelectBo.getStationCodes());
		if (pageFlag) {
			Page<RealWaterSampleComparison> page = PageUtil.pageConvert(IRealWaterSampleComparisonRepository
					.findByTimeBetweenAndIndexCodeInAndStationCodeInOrderByTimeDesc(startDate, endDate, indexList,
							stationCodeList, pageObject.getPageRequest()));
			return new ResultEntity(ResultStatus.SUCCESS, Constants.QUERY_SUCCESS).setPage(page);
		}
		List<RealWaterSampleComparison> list = IRealWaterSampleComparisonRepository
				.findByTimeBetweenAndIndexCodeInAndStationCodeInOrderByTimeDesc(startDate, endDate, indexList,
						stationCodeList);
		return new ResultEntity(ResultStatus.SUCCESS, Constants.QUERY_SUCCESS).setDataList(list);
	}

	@Override
	public ResultEntity automaticAndManualComparisonData(QualityParamSelectBo qualityParamSelectBo,
			PageObject pageObject) {
		boolean pageFlag = pageObject.getPageNumber() != null && pageObject.getPageSize() != null;
		// 验证参数
		ResultEntity resultEntity = IVerificationService.verification(qualityParamSelectBo);
		if (resultEntity.getCode() == 1) {
			return resultEntity;
		}
		Date startDate = DateUtil.stringToDate(qualityParamSelectBo.getStartTime(), DateUtil.DATE_SMALL_STR);
		Date endDate = DateUtil.stringToDate(qualityParamSelectBo.getEndTime(), DateUtil.DATE_SMALL_STR);
		List<String> indexList = ArrayUtils.stringToList(qualityParamSelectBo.getIndexCodes());
		List<String> stationCodeList = ArrayUtils.stringToList(qualityParamSelectBo.getStationCodes());
		if (pageFlag) {
			// 获取分页后的数据集
			return new ResultEntity(ResultStatus.SUCCESS, Constants.QUERY_SUCCESS)
					.setPage(PageUtil.pageConvert(IAutomaticAndManualComparisonRepository
							.findByTimeBetweenAndIndexCodeInAndStationCodeInOrderByTimeDesc(startDate, endDate,
									indexList, stationCodeList, pageObject.getPageRequest())));
		}
		// 查询数据
		List<AutomaticAndManualComparison> list = IAutomaticAndManualComparisonRepository
				.findByTimeBetweenAndIndexCodeInAndStationCodeInOrderByTimeDesc(startDate, endDate, indexList,
						stationCodeList);
		return new ResultEntity(ResultStatus.SUCCESS, Constants.QUERY_SUCCESS).setDataList(list);
	}

}
